--[[

	GModRP - Real Garry's Mod Roleplay.
			By Slob187.
		

]]


DefaultCFG = {} --define the DefaultCFG table
DefaultCFG["knockouttax"] = 30 --knock out tax
DefaultCFG["talkrange"] = 500 --mic talk range
DefaultCFG["doorcost"] = 30 --door cost
DefaultCFG["paydayint"] = 30 --pay day interval ( in seconds )
DefaultCFG["jobchangeint"] = 30 --job change interval (in seconds)
DefaultCFG["startmoney"] = 300 --start money
DefaultCFG["useint"] = 1.5 --use interval
DefaultCFG["maxdoors"] = 5 --max doors owned per person
DefaultCFG["propcost"] = 15 --prop price
DefaultCFG["companyprice"] = 500 --how much it costs to make a company
DefaultCFG["govjobmoney"] = 500 --how much money player must have to use government jobs	
DefaultCFG["handcufftime"] = 60 --time of player being handcuffed (in seconds)	
DefaultCFG["allbuild"] = 0 --all players can build without paying money for props - 1 to enable, 0 to disable
DefaultCFG["allbuildandpay"] = 0 --all players can build, but they pay money for props - 1 to enable, 0 to disable
DefaultCFG["vehiclespawning"] = 0 --vehicle spawning - 1 to enable, 0 to disable
DefaultCFG["ragdollspawning"] = 0 --ragdoll spawning - 1 to enable, 0 to disable
DefaultCFG["effectspawning"] = 0 --effect spawning - 1 to enable, 0 to disable
DefaultCFG["swepspawning"] = 0 --SWEP spawning - 1 to enable, 0 to disable	
DefaultCFG["sentspawning"] = 0 --SENT spawning - 1 to enable, 0 to disable
DefaultCFG["alltool"] = 0 --no tool restrictions - 1 to enable, 0 to disable
DefaultCFG["realistic"] = 1 --realistic sandbox settings (no noclip, damage enabled) - 1 to enable, 0 to disable
DefaultCFG["limitedphysgun"] = 1 --limited physgun (range, weight) - 1 to enable, 0 to disable
DefaultCFG["economy"] = 1 --economy - 1 to enable, 0 to disable
DefaultCFG["economyinterval"] = 180 --economy interval (in seconds)	
DefaultCFG["toolrange"] = 1 --limited toolgun using range - 1 to enable, 0 to disable
DefaultCFG["randomfireint"] = 600 --fire interval (in seconds)


if ( !SERVER ) then return end


require( "glon" )

if file.Exists( "GModRP/settings/settings"..GMRP.version..".txt" ) then

	Configuration = glon.decode( file.Read( "GModRP/settings/settings"..GMRP.version..".txt" ) )
	
else
	
	Configuration = DefaultCFG
	file.Write( "GModRP/settings/settings"..GMRP.version..".txt", glon.encode( Configuration ) )
	
end


function GMRP.addAdmin( sid )

	if ( !file.Exists( "GModRP/admins.txt" ) ) then
	
		file.Write( "GmodRP/admins.txt", glon.encode( {} ) )
		
	end
	
	local adminsTable = glon.decode( file.Read( "GModRP/admins.txt" ) )
	
	if ( !table.HasValue( adminsTable, sid ) ) then
	 
		table.insert( adminsTable, tostring( sid ) )
		file.Write( "GModRP/admins.txt", glon.encode( adminsTable ) )
		
	end	

end


for k, v in pairs( Configuration ) do

	GMRP.command( "cfg_"..k, function( p, c, a )
	
		if ( p:EntIndex() == 0 ) then
	
			if ( !a[1] ) then return end
		
			Configuration[ k ] = tonumber( a[1] )
			file.Write( "GModRP/settings/settings"..GMRP.version..".txt", glon.encode( Configuration ) )
			
			for k2, v2 in pairs( player.GetAll() ) do
			
				v:GreenNotify( "GModRP setting "..k.." has been changed to "..tostring( a[1] ).."." )
				
			end	
			
		end	

	end )

end